Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add Solana Web3.js 2.0 #128

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

[WIP] Add Solana Web3.js 2.0 #128

wants to merge 1 commit into from

Conversation

amilz
Copy link
Collaborator

@amilz amilz commented Oct 31, 2024

  • Creates a Solana Client Factory that allows creation of a client using v1 or v2 of Solana Web3.js following a standard interface
  • Deprecated existing Solana Class (leaving this exposed for now with warning)

TODO:

  • Code Review
  • Tests

Sample Use:

import { ClientVersion, SolanaClientFactory } from './solana';
import { getAddMemoInstruction } from "@solana-program/memo";
import { getTransferSolInstruction } from "@solana-program/system";
import { createKeyPairSignerFromBytes, lamports } from "@solana/web3.js-v2";

const solanaV2client = SolanaClientFactory.createClient(ClientVersion.V2, {
  endpointUrl: 'https://example-endpoint.com',
  wssEndpointUrl: 'wss://example-endpoint.com',
});

async function sendTransaction() {
    const payerSigner = await createKeyPairSignerFromBytes(new Uint8Array([0,0,0...0,0,0]));

    const instructions = [
        getAddMemoInstruction({
            memo: "QN SDK Live on v2!",
        }),
        getTransferSolInstruction({
            amount: lamports(BigInt(1)),
            source: payerSigner,
            destination: payerSigner.address, // use payerSigner.address for demo purposes
        })
    ];

    const signature = await solanaV2client.sendSmartTransaction({
        instructions,
        signer: payerSigner,
    });

    console.log(`Transaction sent! Signature: ${signature}`);
}

sendTransaction().catch((error) => {
    console.error(`❌ Error: ${error}`);
    process.exit(1);
});

- Creates a Solana Client Factory that allows creation of a client using v1 or v2 of Solana Web3.js following a standard interface
- Deprecated existing Solana Class (leaving this exposed for now)
- Since transactions are sent on mainnet, did not write tests -- need to talk to John about testing these
@amilz amilz self-assigned this Oct 31, 2024
@amilz amilz requested a review from johnpmitsch October 31, 2024 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant